﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Qadir;
using System.Windows.Forms;

namespace QadirAsyncAndQadirObjectSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false; //For the sake of this example only. ;)
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Async.GoVoid(() =>
            {
                QadirObject<RichTextBox> qRichTextBox1 = new QadirObject<RichTextBox>(richTextBox1);
                qRichTextBox1.SetProperty<string>("Text", "15...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "14...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "13...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "12...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "11...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "10...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "9...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "8...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "7...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "6...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "5...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "4...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "3...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "2...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "1...");
                System.Threading.Thread.Sleep(1000);
                qRichTextBox1.SetProperty<string>("Text", "Hello from Qadir!");
            }, false);
            //This asynchronous method will run without blocking, so the UI will remain responsive, although the thread sleeps
            //for 15 whole seconds.
        }
    }
}
